import { Body, Controller, Get, ParseIntPipe, Post, Query } from "@nestjs/common";
import { CreateLog, Roles } from "@/common/decorators";
import { Role } from "@/common/enum/role.enum";
import { RequiredPipe } from "@/common/pipes/required.pipe";
import { SysDeptType } from "@/database/entity/SysDeptType";
import { DeptTypeService } from "./dept-type.service";
import { CreateDeptTypeDto } from "./dto/create-dept-type.dto";
import { PageDeptTypeDto } from "./dto/page-dept-type.dto";
import { UpdateDeptTypeDto } from "./dto/update-dept-type.dto";

@Controller("sys/deptType")
export class DeptTypeController {
    constructor(private readonly deptTypeService: DeptTypeService) {}

    /** 新增部门类型 */
    @CreateLog({ module: "系统部门", type: "create", action: "创建系统部门类型" }, SysDeptType)
    @Roles(Role.SUPER_ADMIN)
    @Post("create")
    async create(@Body() type: CreateDeptTypeDto) {
        return this.deptTypeService.create(type);
    }

    /** 删除部门类型 */
    @CreateLog({ module: "系统部门", type: "delete", action: "删除系统部门类型" }, SysDeptType)
    @Roles(Role.SUPER_ADMIN)
    @Post("remove")
    async remove(@Body("id", RequiredPipe) id: string) {
        return this.deptTypeService.remove(id);
    }

    /** 更新部门类型 */
    @CreateLog({ module: "系统部门", type: "update", action: "更新系统部门类型" }, SysDeptType)
    @Roles(Role.SUPER_ADMIN)
    @Post("update")
    async update(@Body() type: UpdateDeptTypeDto) {
        return this.deptTypeService.update(type);
    }

    /** 获取详情 */
    @Get("findById")
    async findById(@Query("id", RequiredPipe) id: string) {
        return this.deptTypeService.findById(id);
    }

    /** 获取部门类型分页列表 */
    @Post("page")
    async page(@Body() data: PageDeptTypeDto) {
        return this.deptTypeService.page(data);
    }

    /** 获取部门选项 */
    @Get("listOptions")
    async listOptions(@Query("level", ParseIntPipe) level: number) {
        return this.deptTypeService.listOptions(level);
    }
}
